<div>
    <div style="margin-bottom: 1em">
        <span style="color: #878787; display: block" id="previous-week-date"></span>
        <span id="previous-week-name"></span>
    </div>
    <div style="font-size: 1.2em; margin-bottom: 1em">
        <span style="color: #878787; display: block" id="this-week-date"></span>
        <span id="this-week-name"></span>
    </div>
    <div style="margin-bottom: 1em">
        <span style="color: #878787; display: block" id="next-week-date"></span>
        <span id="next-week-name"></span>
    </div>
</div>
<script>
    var today = new Date();
    var year = new Date(today.getFullYear(), 0, 1);
    var week = Math.floor(((today - year) / 86400000) / 7) + 1;

    // This is a hack to not mess the checkins order when we change the amount
    // of working groups.
    // Increment this number by one when you realize that after adding
    // working groups the website checkins order messes.
    var magic_number = 4;

    // Add new working groups on the end of the list.
    // When adding/removing working groups adjust magic number to match the
    // current order we see on the page.
    var wgs = [
       {
           name: "Async Foundations",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-async-foundations.toml"
       },
       {
           name: "Traits",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-traits.toml"
       },
       {
           name: "Diagnostics",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-diagnostics.toml"
       },
       {
           name: "Rustc Dev Guide",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-rustc-dev-guide.toml"
       },
       {
            name: "Incremental Compilation",
            url: "https://github.com/rust-lang/team/blob/master/teams/wg-incr-comp.toml"
       },
       {
           name: "LLVM",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-llvm.toml"
       },
       {
           name: "MIR Optimizations",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-mir-opt.toml"
       },
       {
           name: "Polymorphization",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-polymorphization.toml"
       },
       {
           name: "RLS 2.0",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-rls-2.toml"
       },
       {
           name: "Self-Profile",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-self-profile.toml"
       },
       {
           name: "Debugging",
           url: "https://github.com/rust-lang/team/blob/master/teams/wg-debugging.toml"
       }
    ];
    var count = wgs.length % 2 === 0 ? wgs.length : wgs.length + 1;

    function getDateFromWeek(week, year) {
        var day = (2 + (week - 1) * 7);
        return new Date(Date.UTC(year, 0, day));
    }

    function getDateString(date) {
        return date.toISOString().substring(0, 10);
    }

    function updateElementForWeek(week, element, name) {
        var i = (week + magic_number) * 2 % count;

        var message;
        if ((typeof wgs[i + 1]) !== "undefined") {
            message = `<a href="${wgs[i].url}" target="_blank">${wgs[i].name}</a> and <a href="${wgs[i + 1].url}" target="_blank">${wgs[i + 1].name}</a>`;
        } else {
            message = `<a href="${wgs[i].url}" target="_blank">${wgs[i].name}</a>`;
        }

        document.getElementById(element + "-name").innerHTML = message;
        document.getElementById(element + "-date").innerHTML =
            name + ": " +
            getDateString(getDateFromWeek(week, today.getFullYear())) + " - " +
            getDateString(getDateFromWeek(week + 1, today.getFullYear()));
    }

    updateElementForWeek(week + 1, "next-week", "Next Week");
    updateElementForWeek(week, "this-week", "This Week");
    updateElementForWeek(week - 1, "previous-week", "Previous Week");
</script>
